<?php

class MovieController extends Zend_Controller_Action {

    public function init() {
        $this->view->baseUrl = $this->_request->getBaseUrl();
    }

    public function indexAction() {     
         $this->_redirect("Index/index");
    }

    // one movie
    public function movieAction() {
    	$param = $this->getRequest()->getParams();
    	$watchesDB = new Application_Model_Watches;
    	
    	if(isset($param["commentForm"])) {
    		$commentDB = new Application_Model_Comment;
    		$idComment = $commentDB->addComment($param["Comment"], $param["Grade"]);
    		
    		$watchesDB->addWatch($param["Movie_ID"], $idComment, $param["Customer_ID"]);
    		$this->view->alert = "You comment was added !";
    	}
    	
    	if(isset($param['id'])) { 
        	$movieDB = new Application_Model_Movie;
        	$this->view->movie = $movieDB->getMovie2($param['id']);
        	
        	$moviehasactorDB = new Application_Model_MoviehasActor;
            $this->view->actors = $moviehasactorDB->getActors($param['id']);
        	
        	$this->view->comments = $watchesDB->getComments($param['id']);
        	
        	$this->view->title = "Movie - ".$this->view->movie["Title"];
    	} else {
    		 $this->_redirect("Index/index");
    	}
    }
    
    public function searchAction() {
        $param = $this->getRequest()->getParams();
        
        $movieDB = new Application_Model_Movie;
        $this->view->results = $movieDB->search($param['text']);
        $this->_helper->layout->disableLayout();
    }

}

